package cn.bandeqing.unipush2.util;

import lombok.extern.slf4j.Slf4j;
import org.dromara.hutool.core.data.id.IdUtil;
import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.http.client.Request;
import org.dromara.hutool.http.client.Response;
import org.dromara.hutool.http.client.engine.jdk.JdkClientEngine;
import org.dromara.hutool.http.meta.ContentType;
import org.dromara.hutool.http.meta.HeaderName;
import org.dromara.hutool.http.meta.Method;
import org.dromara.hutool.json.JSONObject;
import org.dromara.hutool.json.JSONUtil;

import java.util.HashMap;
import java.util.UUID;

@Slf4j
public class Unipush2Util {

    private static final JdkClientEngine engine = new JdkClientEngine();

    public static void sendMsg(String title, String content, String requestId, Object data, String... cids) {
        JSONObject entries = JSONUtil.ofObj();

        entries.set("title", title);
        entries.set("content", content);
        entries.set("requestId", requestId);
        entries.set("data", data);
        entries.set("cids", cids);

        String param = entries.toString();
//        System.out.println("param = " + param);
        log.info("param = {}", param);

        Request request = Request.of("https://fc-mp-dc8de1a0-94d9-46f4-99c0-ecbbbfe9d378.next.bspapp.com/sendMsg")
                .header(HeaderName.CONTENT_TYPE, ContentType.JSON.getValue())
                .method(Method.POST)
                .body(entries.toString());
        Response resp = engine.send(request);
        String res = resp.bodyStr();
//        System.out.println("res = " + res);
        log.info("res = {}", res);
    }

//    public static void main(String[] args) {
//        HashMap<String, Integer> data = MapUtil.of("orderId", 12312312);
//        data.put("msgType", 0);
//
//        sendMsg("系统派单通知", "您有一个新的待处理订单", UUID.randomUUID().toString(), JSONUtil.toJsonStr(data), "7286ec914cb4ea4e48b70997a0a4ea1c");
//    }

//    public static void main(String[] args) {
//        System.out.println(IdUtil.randomUUID());
//    }

}
